//
//  AddMeterMultipleSetsCell.swift
//  Employee
//
//  Created by tancheng on 2018/6/21.
//  Copyright © 2018年 remotevillage. All rights reserved.
//

import UIKit

class AddMeterMultipleSetsCell: UITableViewCell, UITextFieldDelegate {

    static let reuseIdentifer = "AddMeterMultipleSetsCell"
    
    @IBOutlet weak var nameLab1: UILabel!
    @IBOutlet weak var nameLab2: UILabel!
    
    @IBOutlet weak var merterReadingTf: UITextField!
    @IBOutlet weak var meterNumerTf: UITextField!
    
    var updateBlock:((String,Int)->())?
    
    
    var paramModel: AddMeterModel? {
        didSet {
           updateData()
        }
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        let placeHolderColor = UIColor.hex("#323C49", alpha: 0.5)
        
        merterReadingTf.setValue(placeHolderColor, forKeyPath: "_placeholderLabel.textColor")
        meterNumerTf.setValue(placeHolderColor, forKeyPath: "_placeholderLabel.textColor")
        
        meterNumerTf.delegate = self
        merterReadingTf.delegate = self
        
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    func updateData() {
        
        nameLab1.text = paramModel?.name.first
        nameLab2.text = paramModel?.name[1]
        
        meterNumerTf.text = paramModel?.inputText.first
        merterReadingTf.text = paramModel?.inputText[1]
    }
    
    //delegate
    func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
        return true
    }
    
    func textFieldDidEndEditing(_ textField: UITextField) {
        if meterNumerTf == textField {
            self.updateBlock?(textField.text!,0)
        }else {
            self.updateBlock?(textField.text!,1)
        }
        
    }
    
}
